/*
 * Copyright 2025 The Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *@file    : rotation_local_parameterzation.h
 *@brief   : rotation_local_parameterzation
 *@authors : zhanglei
 *@version : v1.0
 *@data    : 2025/9/14
 *
 */
#ifndef ROTATION_LOCAL_PARAMETERIZATION_H_
#define ROTATION_LOCAL_PARAMETERIZATION_H_
#include <vector>
#include <memory>

#include <ceres/ceres.h>
#include <ceres/local_parameterization.h>

#include "common/state.h"

namespace optimizer {

class RotationLocalParameterization : public ceres::LocalParameterization  {
public:
    virtual int GlobalSize() const { return 1; };
    virtual int LocalSize() const { return 1; };

    virtual bool Plus(const double *x, const double *delta, double *x_plus_delta) const;
    virtual bool ComputeJacobian(const double *x, double *jacobian) const;

    static double NormalizeAngle(double angle) {
        while (angle > M_PI) angle -= 2. * M_PI;
        while (angle < -M_PI) angle += 2. * M_PI;
        return angle;
    }
};

}

#endif 
